package org.jadestudio.home.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.jadestudio.home.dao.GameDao;

public class GameService {
	private GameDao gameDao; 
	
	public GameDao getGameDao() {
		return gameDao;
	}

	public void setGameDao(GameDao gameDao) {
		this.gameDao = gameDao;
	}
	/**
	 * 获取首页游戏列表
	 * @param 
	 */
	public List getHomePageGameList(){
		try {
			List<java.util.Map> gameList = gameDao.getHomePageGameList();
			return gameList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 	获取当月游戏发售表 
	 * @param 
	 */
	public List getGameRetailList(int year,int month){
		try {
			List<java.util.Map> gameList = gameDao.getGameRetailList(year,month);
			return gameList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 获取游戏类型列表 
	 */
	public List<java.util.Map> getGameTypeList(){
		try {
			List<java.util.Map> gameTypeList = gameDao.getGameTypeList();
			java.util.Map allTypeMap = new java.util.HashMap<Object, Object>();
			allTypeMap.put("game_type_id", "");
			allTypeMap.put("game_type_name", "全部");
			gameTypeList.add(0, allTypeMap);
			return gameTypeList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 获取游戏类型列表 
	 */
	public List<java.util.Map> getGameInitialList(){
		try {
			List<java.util.Map> gameInitialList = new ArrayList<java.util.Map>();
			java.util.Map allInitialMap = new java.util.HashMap<Object, Object>();
			allInitialMap.put("game_initial_id", "");
			allInitialMap.put("game_initial_name", "全部");
			gameInitialList.add(allInitialMap);
			
			for(char i='A';i<='Z';i++)
			{
				java.util.Map letterTypeMap = new java.util.HashMap<Object, Object>();
				letterTypeMap.put("game_initial_id", String.valueOf(i));
				letterTypeMap.put("game_initial_name", String.valueOf(i));
				gameInitialList.add(letterTypeMap);
			}
			
			java.util.Map allNumMap = new java.util.HashMap<Object, Object>();
			allNumMap.put("game_initial_id", "num");
			allNumMap.put("game_initial_name", "数字");
			gameInitialList.add(allNumMap);
			
			return gameInitialList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/**
	 * 获取游戏平台列表 
	 */
	public List<java.util.Map> getGamePlatformList(){
		try {
			List<java.util.Map> gamePlatformList = gameDao.getGamePlatformList();
			java.util.Map allPlatformMap = new java.util.HashMap<Object, Object>();
			allPlatformMap.put("game_platform_id", "");
			allPlatformMap.put("game_platform_name", "全部");
			gamePlatformList.add(0, allPlatformMap);
			return gamePlatformList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/*
	 * 游戏列表筛选
	 */
	public List<java.util.Map> getGameList(String category,String initial,String platform,int pageindex,int pagesize) throws SQLException{
		try {
			List<java.util.Map> gameList = gameDao.getGameList(category, initial, platform, pageindex, pagesize);
			return gameList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	
	/*
	 * 获取游戏筛选列表总页数
	 */
	public int getGamePageCount(String category,String initial,String platform,int pagesize) throws SQLException{
		try {
			int pageCount = gameDao.getGamePageCount(category, initial, platform, pagesize);
			return pageCount;
			
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	
	/*
	 * 获取指定搜索关键字游戏（前12个）
	 */
	public List<java.util.Map> searchGamesByKeyname(String keyname){
		try {
			List<java.util.Map> gameList = gameDao.searchGamesByKeyname(keyname);
			return gameList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 获取游戏详情BYID
	 */
	public java.util.Map getGameDetail(String id){
		try {
			java.util.Map gameDetail = gameDao.getGameDetail(id);
			return gameDetail;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 获取游戏平台ID对应名称
	 */
	public List<java.util.Map> getGamePlatformById(String ids){
		try {
			List<java.util.Map> gamePlatforms = gameDao.getGamePlatformById(ids);
			return gamePlatforms;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 获取游戏截图列表
	 */
	public List<java.util.Map> getGameScreenshotList(String id){
		try {
			List<java.util.Map> gameScreenshots = gameDao.getGameScreenshotList(id);
			return gameScreenshots;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	
	/*
	 * 获取类似游戏列表
	 */
	public List<java.util.Map> getSimilarGameList(String id,String tag){
		try {
			List<java.util.Map> gameSimilars = gameDao.getSimilarGameList(id,tag);
			return gameSimilars;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	
	/*
	 * 获取游戏相关文章列表
	 */
	public List<java.util.Map> getGameArticleList(String id){
		try {
			List<java.util.Map> articleList = gameDao.getGameArticleList(id);
			return articleList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 获取指定发行/开发厂商的游戏
	 */
	public List<java.util.Map> getGamesListByCompany(String id,String dev_company,String publish_company_id){
		try {
			List<java.util.Map> articleList = gameDao.getGamesListByCompany(id, dev_company, publish_company_id);
			return articleList;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 获得游戏投票情况
	 */
	public java.util.Map getGameVotes(String id,String ip){
		try {
			List<java.util.Map> gameVoteList = gameDao.getGameVotes(id,ip);
			java.util.Map result = new java.util.HashMap();
			for(int i=0;i<gameVoteList.size();i++){
				result.put(gameVoteList.get(i).get("game_score_value").toString(), gameVoteList.get(i).get("count"));
			}
			return result;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	
	/*
	 * 文章投票
	 */
	public int voteGame(String game_id, int score, String ip) throws SQLException{
		try {
			return gameDao.voteGame(game_id, score, ip);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	
	/*
	 * 获取游戏下载链接
	 */
	public List<java.util.Map> getGameDownloads(String id){
		try {
			return gameDao.getGameDownloads(id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	
	/*
	 * 获取游戏购买链接
	 */
	public List<java.util.Map> getGamePurchases(String id){
		try {
			return gameDao.getGamePurchases(id);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}	
}
